package cp.remote.timer;

import android.app.Activity;
import android.os.Handler;
import android.widget.EditText;
import cp.remote.R;
import cp.remote.network.Network;

public class ConfigTimer implements Runnable {

    private Handler handler;
    private EditText txt;
    private Activity conf;
    private Network w;

    public ConfigTimer(Handler handler, Activity conf, Network w) {
        this.handler = handler;
        this.conf = conf;
        this.txt = ((EditText)conf.findViewById(R.id.conf_textarea_progress));
        this.w = w;
    }

    public void run() {
        if (w.isConnected() || w.isError()) {
            String t = w.getName() + ": ";
            if (w.isError()) {
                txt.append(t + w.getErrormsg() + "\n");                
            } else {
                txt.append(t + " connected\n");     
                conf.invalidateOptionsMenu();   // Refresh option menu         
            }
        }else{
            handler.postDelayed(this, 50);
        }
    }

}
